'use strict';

/*var app = angular.module('app');*/
angular.module('app').controller('authImportController', [ '$rootScope', '$scope', '$http', '$state','toaster','$modal',
    function($rootScope, $scope, $http, $state,toaster,$modal) {
        $scope.title = '人员管理';
        $scope.param = { };
        $scope.loading = false;

        $scope.search = function () {
            $scope.loading = true;
            if($scope.pageFlag != 1){//未点击翻页
                $scope.param.pageNum=1;//将页码设置为1，即跳转回第一页
            }else{//点击翻页
                $scope.pageFlag = 2;//将开关值设置为2
            }
            $.ajax({
                type: 'POST',
                dataType: 'json',
                contentType:'application/json;charset=UTF-8',
                url : 'dac/authm/cardAuth/excelLog/list',
                data: angular.toJson($scope.param)
            }).then(function(result) {
                console.log(result);
                $scope.loading = false;
                if (result.httpCode == 200) {
                    $scope.pageInfo = result;
                } else {
                    $scope.msg = result.msg;
                }
                $scope.$apply();
            });
        }

        //从本地获取localstorage数据，对权限按钮做隐藏
        var personAuth =localStorage.getItem("PersonAuth");//获取PersonAuth的值
        console.log(personAuth);
        personAuth = personAuth.split(',');
        for(var i = 0;i<personAuth.length;i++){
            if(personAuth[i]=='main.member.read'){
                $scope.read = true;
            }
            if(personAuth[i]=='main.member.add'){
                $scope.add = true;
            }
            if(personAuth[i]=='main.member.update'){
                $scope.update = true;
            }
            if(personAuth[i]=='main.member.delete'){
                $scope.dele = true;
            }
        }




        $scope.search();

        $scope.clearSearch = function() {
            $scope.param.keyword= null;
            $scope.search();
        }

        $scope.disableItem = function(id, enable) {

        }

        $scope.delItem = function(id) {
            if (confirm("确认删除吗？")==true)
            {
                $.ajax({
                    type: 'DELETE',
                    dataType: 'json',
                    contentType:'application/json;charset=UTF-8',
                    url : 'dac/userManager/delete',
                    data: angular.toJson({'personId': id})
                }).then(function(result) {
                    if (result.httpCode == 200) {
                        toaster.clear('*');
                        toaster.pop('success', '', "删除成功");
                        $scope.search();
                    }
                    else
                    {
                        toaster.clear('*');
                        toaster.pop('false', '', result.msg);
                    }
                    $scope.$apply();
                });
            }
            else
            {
                $state.go('main.member.list');
            };



        };


        $scope.openDevice = function(id) {
            alert(id);
            var modalInstance = $modal.open({
                templateUrl : 'delete.html',//script标签中定义的id
                controller : 'deleteModalCtrl',//modal对应的Controller
                size: 'lg'
            });

            $scope.ok = function () {
                $.ajax({
                    type: 'DELETE',
                    dataType: 'json',
                    contentType:'application/json;charset=UTF-8',
//	   				url : 'dac/userManager/delete',
                    url : '#',
                    data: angular.toJson({'personId': id})
                }).then(function(result) {
                    if (result.httpCode == 200) {
                        alert("删除成功");
                        $scope.search();
                    } else {
                        alert("删除失败");
                    }

                });

                $scope.cancel = function () {
                    $modalInstance.dismiss('cancel');
                };

            }
        }

        // 翻页
        $scope.pagination = function (page) {
            $scope.param.pageNum=page;
            $scope.pageFlag = 1;//将开关值设置为1
            $scope.search();
        };
    } ]);
